using System;
using System.Collections.Generic;
using System.Text;
using ValidateContentDeploymentPackage;

namespace cmdValidateContentDeploymentPackage
{
    public class Parameters
    {
        public Parameters()
        {
        }
        private string url;
        private string contentDeploymentPackage;
        public string ContentDeploymentPackage
        {
            get
            {
                return this.contentDeploymentPackage;
            }
            set
            {
                this.contentDeploymentPackage = value;
            }
        }

        public string Url
        {
            get
            {
                return this.url;
            }
            set
            {
                this.url = value;
            }
        }

        /// <summary>
        /// This method reads the parameters specified
        /// </summary>
        /// <returns>true for success</returns>
        public bool ReadParameters(string[] args)
        {
            bool returnValue = true;
            for (int i = 0; i < args.GetLength(0) - 1; i += 2)
            {
                string lowerarg = args[i];
                string data = args[i + 1];
                switch (lowerarg)
                {

                    case "-url":
                        Url = data;
                        break;
                    case "-package":
                        ContentDeploymentPackage = data;
                        break;

                }
            }
            if (Url != null && Url.Length > 0)
            {

            }
            else
            {
                returnValue = false;
                Console.WriteLine("The -url parameter is mandatory");
            }
            return returnValue;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: {0} -url sitecollectionUrl -package manifest.xml", Environment.CommandLine);
                return;
            }
            Parameters p = new Parameters();
            if (p.ReadParameters(args))
            {
                ValidateContentDeploymentPackage.Validator validator = new ValidateContentDeploymentPackage.Validator();
                validator.ValidateFile(p.ContentDeploymentPackage, p.Url);
            }

        }
    }
}
